//
//  RegisterViewController.m
//  FengyuanXS
//
//  Created by 王冬 on 2020/7/27.
//  Copyright © 2020 王冬. All rights reserved.
//

#import "RegisterViewController.h"
#import "ClassViewController.h"
@interface RegisterViewController ()
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *buneLabel;
@property (weak, nonatomic) IBOutlet UITextField *phoneText;
@property (weak, nonatomic) IBOutlet UITextField *codeText;
@property (weak, nonatomic) IBOutlet UIButton *codeBtn;
@property (nonatomic, copy) NSString *classID;
@property (nonatomic, copy) NSString *sectionID;
@property (nonatomic, copy) NSString *companyID;
- (IBAction)codeBtn:(UIButton *)sender;

@end

@implementation RegisterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"新用户注册";
    self.nameLabel.text = [NSString stringWithFormat:@"姓名：%@",self.model.real_name];
    self.buneLabel.text = [NSString stringWithFormat:@"部门：%@",self.model.section_name];
    self.sectionID = self.model.section_id;
    self.companyID = self.model.company_id;
    
    // Do any additional setup after loading the view.
}
- (IBAction)bumenBtn:(UIButton *)sender {
    
    ClassViewController *testVC = [ClassViewController loadStroyboard:[ClassViewController new]];
    WS(weakSelf);
    testVC.claasName = ^(NSString * _Nonnull name, NSString * _Nonnull classID, NSString * _Nonnull companyID, NSString * _Nonnull company) {
        weakSelf.sectionID = classID;
        weakSelf.companyID = companyID;
        weakSelf.buneLabel.text = [NSString stringWithFormat:@"部门：%@",name];
    };
    
    STPopupController *popupController = [[STPopupController alloc] initWithRootViewController:testVC];
    popupController.style = STPopupStyleFormSheet;
    popupController.transitionStyle = STPopupTransitionStyleFade;
    popupController.containerView.layer.cornerRadius = 5.0f;
    [popupController setNavigationBarHidden:YES];
    [popupController presentInViewController:self];
    
}
- (IBAction)registerBtn:(BoardButton *)sender {
    [[ApiManager ShardInstance]userRegisteruserID:self.model.id mobile:self.phoneText.text section_id:self.sectionID company_id:self.companyID captcha:self.codeText.text resultBlock:^(NSDictionary *data, NSError *error) {
        
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        
        if (model.code == 1) {
            NSInteger index=[[self.navigationController viewControllers]indexOfObject:self];
            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:index-2]animated:YES];
        }
        [[ToastManager shardInstance]showToast:@"注册成功"];
        
    }];
    
    
}


- (IBAction)codeBtn:(UIButton *)sender {
    
    [[ApiManager ShardInstance]codeuserID:self.model.id mobile:self.phoneText.text type:@"1" resultBlock:^(NSDictionary *data, NSError *error) {
        BaseModel *model = [BaseModel mj_objectWithKeyValues:data];
        if (model.code == 1) {
            [AuthCodeManager getValidCode:sender];
            [[ToastManager shardInstance]showToast:model.msg];
        }
        
    }];
}
@end
